//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    isaddress:'',
    animationData: {},
    isBig: true,
    setInter: '' //计时器
  },
  getUserInfo: function(e) {
    if (e.detail.userInfo == '' || e.detail.userInfo == 'undefined' || e.detail.userInfo == undefined) {
      wx.showToast({
        title: '请同意授权',
        icon: 'success'
      })
      return;
    }
    wx.showToast({
      title: '授权成功',
      icon: 'success'
    })
    

    app.globalData.userInfo = e.detail.userInfo;
    console.log(app.globalData.userInfo)
    wx.setStorageSync('userinfo', e.detail.userInfo);
    console.log('userinfo', e.detail.userInfo);
    console.log('登陆推荐人ID', app.recomendID)
    wx.login({
      success: function(res) {
        if (res.code) {
          var rawData = e.detail.rawData;
          var signature = e.detail.signature;
          var encryptedData = e.detail.encryptedData;
          var iv = e.detail.iv;
          wx.request({
            url: app.serverUrl + 'About/userLogin',
            data: {
              "code": res.code,
              "rawData": rawData,
              "signature": signature,
              'iv': iv,
              'encryptedData': encryptedData,
              'tid': app.recomendID
            },
            success: function(e) {
              console.log('userLogin', e)
              app.openid = e.data.data.openid;
              wx.setStorageSync(app.globalData.OPENID_KEY, e.data.data.openid);
              wx.switchTab({
                url: '/pages/main/main',
              })
              // if (!e.data.data.usertype) {
               
              // }else{
              //   wx.navigateBack({})
              // }
              
            }
          })
        } else {
          //失败
        }
      }
    })
  },
  onLoad: function() {

  },
  onShow: function() {
    var animation = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease',
    })

    this.animation = animation

    animation.scale(1.5, 1.5).step()
    this.setData({
      animationData: animation.export(),
      isBig: true
    })

    this.data.setInter = setInterval(function() {
      if (this.data.isBig) {
        animation.scale(1, 1).step()
        this.setData({
          animationData: animation.export(),
          isBig: false
        })
      } else {
        animation.scale(1.5, 1.5).step()
        this.setData({
          animationData: animation.export(),
          isBig: true
        })
      }

    }.bind(this), 1000)
  },
  onHide: function() {
    clearInterval(this.data.setInter) //清除计时器
  }
})